package org.pro.core.social.weixin.config;

import org.pro.core.properties.SecurityProperties;
import org.pro.core.properties.WeixinProperties;
import org.pro.core.social.weixin.connect.WeixinConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
import org.springframework.social.config.annotation.SocialConfigurerAdapter;
/**
 * 配置数据源 
 * @author luoqiz
 *
 */
import org.springframework.social.security.SpringSocialConfigurer;

@Configuration
public class WeixinSocialConfig extends SocialConfigurerAdapter {
	
	@Autowired
	private SecurityProperties securityProperties;

	
	@Override
	public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
		 WeixinProperties weixin = securityProperties.getSocialProperties().getWeixinProperties();
		WeixinConnectionFactory weixinConnectionFactory = new WeixinConnectionFactory(weixin.getProviderId(), weixin.getAppId(),
				weixin.getAppSecret());
		cfConfig.addConnectionFactory(weixinConnectionFactory);
	}

	@Bean
	public SpringSocialConfigurer weixinSocialConfigurer() {
		return new SpringSocialConfigurer();
	}


}
